package edu.buaa.act.travel.m.service;

import java.util.Map;

import edu.buaa.act.travel.m.Log;

import android.os.Handler;
import android.os.Message;

public class DataService {
	
	private static final String TAG = DataService.class.getSimpleName();
	
	public static void get(final String url, final Handler handler, 
			final int success, final int fail) {
		new Thread() {
			public void run() {
				final Message msg = new Message();
				try {
					final String result = HttpService.get(url);
					Log.log(TAG, "result " + result);
					msg.obj = result;
					msg.what = success;
				} catch (Exception e) {
					msg.what = fail;
					e.printStackTrace();
				}
				
				handler.sendMessage(msg);
			}
		}.start();
	}
	
	public static void post(final String url, final Map<String, String> params,
			final Handler handler, final int success, final int fail) {
		new Thread() {
			public void run() {
				final Message msg = new Message();
				try {
					final String result = HttpService.post(url, params);
					Log.log(TAG, "result " + result);
					msg.obj = result;
					msg.what = success;
				} catch (Exception e) {
					msg.what = fail;
					e.printStackTrace();
				}
				
				handler.sendMessage(msg);
			}
		}.start();
	}
}
